package com.ysqcould.web.controller.allocation;


import com.ysqcould.allocation.domain.MessageConfig;
import com.ysqcould.allocation.service.IMessageConfigService;
import com.ysqcould.common.annotation.Log;
import com.ysqcould.common.core.controller.BaseController;
import com.ysqcould.common.core.domain.AjaxResult;
import com.ysqcould.common.core.page.TableDataInfo;
import com.ysqcould.common.enums.BusinessType;
import com.ysqcould.common.utils.poi.ExcelUtil;
import com.ysqcould.revita.domain.GslNotice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 模板消息配置Controller
 * 
 * @author ruoyi
 * @date 2022-06-29
 */
@RestController
@RequestMapping("/allocation/config")
public class MessageConfigController extends BaseController
{
    @Autowired
    private IMessageConfigService messageConfigService;

    /**
     * 查询模板消息配置列表
     */
    @PreAuthorize("@ss.hasPermi('allocation:config:list')")
    @GetMapping("/list")
    public TableDataInfo list(MessageConfig messageConfig)
    {
        startPage();
        List<MessageConfig> list = messageConfigService.selectMessageConfigList(messageConfig);
        return getDataTable(list);
    }

    /**
     * 导出模板消息配置列表
     */
    @PreAuthorize("@ss.hasPermi('allocation:config:export')")
    @Log(title = "模板消息配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MessageConfig messageConfig)
    {
        List<MessageConfig> list = messageConfigService.selectMessageConfigList(messageConfig);
        ExcelUtil<MessageConfig> util = new ExcelUtil<MessageConfig>(MessageConfig.class);
        util.exportExcel(response, list, "模板消息配置数据");
    }

    /**
     * 获取模板消息配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('allocation:config:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(messageConfigService.selectMessageConfigById(id));
    }

    /**
     * 新增模板消息配置
     */
    @PreAuthorize("@ss.hasPermi('allocation:config:add')")
    @Log(title = "模板消息配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MessageConfig messageConfig)
    {
        messageConfig.setAsId(getUserId());
        return toAjax(messageConfigService.insertMessageConfig(messageConfig));
    }

    /**
     * 修改模板消息配置
     */
    @PreAuthorize("@ss.hasPermi('allocation:config:edit')")
    @Log(title = "模板消息配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MessageConfig messageConfig)
    {
        return toAjax(messageConfigService.updateMessageConfig(messageConfig));
    }

    /**
     * 删除模板消息配置
     */
    @PreAuthorize("@ss.hasPermi('allocation:config:remove')")
    @Log(title = "模板消息配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(messageConfigService.deleteMessageConfigByIds(ids));
    }
    /**
     * 状态修改
     */
    @Log(title = "模板消息配置", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody MessageConfig config)
    {
        return toAjax(messageConfigService.updateStatus(config));
    }
}
